package com.zryc.service;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zryc.mapper.ProductMapper;
import com.zryc.shop.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

@Service
public class ProductService implements IService<Product> {
    @Autowired
    private ProductMapper productMapper;

    /**
     * 新增一个扣库存的方法
     * @param pid   商品ID
     * @param num   扣库存的数量
     */
    public void reduceInventory(Integer pid,Integer num){
//        int n=100/0;
        Product product=this.getById(pid);  //根据id查询商品信息
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("pid",pid);
        wrapper.set("stock",product.getStock() - num);
        this.update(wrapper);//更新商品库存
    }

    @Override
    public BaseMapper<Product> getBaseMapper() {
        return productMapper;
    }

    @Override
    public boolean saveBatch(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(Product entity) {
        return false;
    }

    @Override
    public Product getOne(Wrapper<Product> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<Product> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<Product> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public Class<Product> getEntityClass() {
        return null;
    }
}
